LIBRARY_PATH = /usr/local/lib
INCLUDE_PATH = /usr/local/include

#########Compilation Flags#######################################

#includes
CXXFLAGS+= -Wall -I. -fPIC


OBJECTS      =  src/bio_molecular/bio_molecular.o

BIOPP_INCLUDE     =  biopp/biopp.h
BIO_INCLUDE       =  biopp/bio_molecular
PROT_INCLUDE      =  biopp/prot_structure
RNA_INCLUDE       =  biopp/rna_structure

LIB_VERSION =1.0

CXX          = g++

LIBS		 =

LDFLAGS		 =


ifeq ($(DEBUG),on)
    CXXFLAGS+= -ggdb3
endif

ifeq ($(STL_DEBUG_ENABLE),on)
	CXXFLAGS+= -ggdb3 -DSTL_DEBUG_ENABLE
endif

LIBS = 

all: biopp
		
biopp:  $(OBJECTS) 
		$(CXX) -shared -Wl,-soname,libbiopp.so.1 -o libbiopp.so.$(LIB_VERSION) $(OBJECTS) $(LDFLAGS) $(LIBS)

.PHONY: cleanall cleanobj install

clean: cleanall

cleanall : cleanobj 

cleanobj :
	rm -f *.o */*.o */*/*.o */*/*/*.o
	rm -f libbiopp.so.$(LIB_VERSION) 

install:
	cp libbiopp.so.$(LIB_VERSION) $(LIBRARY_PATH)
	ln -sf $(LIBRARY_PATH)/libbiopp.so.$(LIB_VERSION) $(LIBRARY_PATH)/libbiopp.so.1
	ln -sf $(LIBRARY_PATH)/libbiopp.so.$(LIB_VERSION) $(LIBRARY_PATH)/libbiopp.so

	mkdir -p $(INCLUDE_PATH)/biopp
	cp $(BIOPP_INCLUDE) $(INCLUDE_PATH)/biopp
	cp -R $(BIO_INCLUDE) $(INCLUDE_PATH)/biopp/
	cp -R $(PROT_INCLUDE) $(INCLUDE_PATH)/biopp/
	cp -R $(RNA_INCLUDE) $(INCLUDE_PATH)/biopp/
	ldconfig

# Find all sources with available tests
TEST_SRCS := $(patsubst ./%, %, $(shell find|egrep "_test\.cpp$$") )
TEST_BINS := $(patsubst %.cpp, %, $(TEST_SRCS))

test:
	@# Run all tests
	for TEST in $(TEST_BINS); do \
		make "$$TEST"_run; \
		done

%_test: %_test.cpp
	@# Compile the source and link with the real .o
	g++ $(OBJECTS) $@.cpp -o $@ \
		$(CXXFLAGS) $(LDFLAGS) \
		-lgtest_main -lgmock -lpthread

%_test_run: %_test
	@# Zomg magic magic - this will make the test and then run it
	./$<

